//
//  RoadDetialTableViewCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 lushan. All rights reserved.
//

#import "RoadDetialTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation RoadDetialTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    self.siteLabel = [[UILabel alloc] initWithFrame:CGRectMake(5 * WID, 10 * HEI, WIDTH - 10 * WID, 12 * HEI)];
    [self.contentView addSubview:self.siteLabel];
    
    self.roadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.siteLabel.frame.origin.x, self.siteLabel.frame.origin.y +self.siteLabel.frame.size.height + 20 * HEI, WIDTH - 10 * WID, 220 * HEI)];
    [self.contentView addSubview:self.roadImageView];
    
    self.bigLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.siteLabel.frame.origin.x, self.roadImageView.frame.origin.y + self.roadImageView.frame.size.height + 10 * HEI, WIDTH - 10 * WID, 1000)];
    self.bigLabel.numberOfLines = 0;
    [self.contentView addSubview:self.bigLabel];
}


-(void)setRoadDetailModel:(RoadDetailModel *)roadDetailModel{

    _roadDetailModel = roadDetailModel;
    
    self.l = [NSString stringWithFormat:@"  %@",self.roadDetailModel.entry_name];
    
    [self.roadImageView sd_setImageWithURL:[NSURL URLWithString:self.roadDetailModel.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    
    self.bigLabel.text = self.roadDetailModel.tips;
    [self.bigLabel sizeToFit];
    
    CGFloat cellHeight = [RoadDetialTableViewCell heightForContent:self.roadDetailModel.tips];
    CGRect tempFrame = self.bigLabel.frame;
    tempFrame.size.height = cellHeight;
    self.bigLabel.frame = tempFrame;
}


-(void)setS:(NSString *)s{
    _s = s;
    self.siteLabel.text = [NSString stringWithFormat:@"第%@站:%@",self.s,self.l];
    
}


+(CGFloat)heightForContent:(NSString *)content{
    CGSize size = CGSizeMake(WIDTH - 20 * WID, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0],NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
